package com.itjiange.reglg.utils;

import com.itjiange.reglg.common.ErrorCode;
import com.itjiange.reglg.exception.BussinessException;

/**
 * 异常抛出工具
 *
 * @author ItJiange
 * @date 2023/11/15
 */
public class ThrowUtils {

    /**
     * 条件成立立即抛异常
     * @param condition
     * @param code
     * @param message
     */
    public static void throwif(boolean condition, RuntimeException runtimeException) {
        if (condition) {
            throw runtimeException;
        }
    }

    /**
     * 条件成立立即抛异常
     * @param condition
     * @param code
     * @param message
     */
    public static void throwif(boolean condition, int code, String message) {
        if (condition) {
            throw new BussinessException(code, message);
        }
    }

    /**
     * 条件成立立即抛异常
     * @param condition
     * @param errorCode
     */
    public static void throwif(boolean condition, ErrorCode errorCode) {
        if (condition) {
            throw new BussinessException(errorCode);
        }
    }

    /**
     * 条件成立立即抛异常
     * @param condition
     * @param errorCode
     * @param message
     */
    public static void throwif(boolean condition, ErrorCode errorCode, String message) {
        if (condition) {
            throw new BussinessException(errorCode, message);
        }
    }
}
